import axios from 'axios'
const service = axios.create({
  baseURL: process.env.APP_BASE_URL,
  // withCredentials: true,
  timeout: 5000
})

service.interceptors.request.use(config => {
  return config
})

service.interceptors.response.use( response => {
  const res = response.data

  if (res.code === 200 || res.code === 20000) {
    return Promise.resolve(res)
  } else {
    Promise.reject(new Error(res.msg || 'Error'))
  }
},
  error => {
    return Promise.reject(error)
  })

export default service
